Learning Objectives

After completing this lesson, you'll be able to:

Instructions

In this lesson, you will:

Resources

Introduction

Creating attributes and setting a value are the primary attribute functions used within FME. When an attribute is created, its value can be set in several ways.

The main transformers capable of creating an attribute - and setting its value - are:

Note

The AttributeCopier and AttributeRenamer transformers can only set an attribute value where the attribute doesn't exist.

The AttributeManager

We'll concentrate on the AttributeManager for most operations, so here is a quick overview of that transformer.

The AttributeManager parameters dialog has several fields: Input Attribute, Output Attribute, Attribute Value, and Action. Uniquely among attribute-handling transformers, it is automatically filled in with the details of the attributes connected to it:

AttributeManager dialog

The user can set the action field, but the transformer will also set it automatically if you change the other fields.

Manually Create an Attribute

If you enter a new attribute name into the Output Attribute field, FME will create it in the output.

Adding a new attribute called City

The text <Add new Attribute> highlights where you can create a new attribute. By default, when the Attribute Value field is empty, a new attribute has no value.

Set a Fixed Attribute Value

A fixed (or constant) value for an attribute can be created by simply entering a value into the Value field:

Set a fixed attribute value in the AttributeManager

Here, for example, a new attribute called City is given a fixed value of Vancouver. The transformer will set that value for every record entering the transformer.

The user has also assigned a fixed value to the existing attribute NeighborhoodName. They gave it the value "Kitsilano." Notice how entering a value into that field automatically changes the Action field from "Do Nothing" to "Set Value."

Note

The AttributeManager, AttributeCreator, and some other attribute transformers that can set values will overwrite existing values. If you are creating attributes and setting values, they will also silently overwrite those attributes. For example, say your data already has an existing attribute called UpdatedDate, and every record has a value of 1698254789. Then, you create a new attribute called UpdatedDate using an AttributeCreator and set the value to the current date time, e.g., 11-02-2023. FME will overwrite the old attribute with this new value. If you don't see the values you expect for an attribute, please ensure your transformers are correctly configured.

Constructing Attributes

Besides constant attribute values, FME also allows you to construct values using string manipulation and arithmetic calculations. This procedure is achieved by clicking on the arrow in the Attribute Value field and selecting either Open Text Editor or Open Arithmetic Editor:

Clicking on the arrow in the Attribute Value field

This method is advantageous because the attribute no longer needs to be a fixed value; it can be constructed from a mix of existing attributes, parameters, and constants.

Text Editor

The Text Editor - as you would expect - allows you to construct a text value. It includes all the usual string-handling functionality you need, such as concatenation, trimming, padding, and case-changing.

The Text Editor looks like this:

FME Feature Attributes in the Text Editor

Here, the user constructs an address string by concatenating various existing attributes with some fixed characters (the commas).

Notice the menu on the left-hand side. Existing attributes are listed here, and you can add them to the string by double-clicking them. Also, notice the other menu options. Maybe the most important for text are String Functions:

A partial list of string functions

These functions can be used to manipulate strings. For example, here, the user is making sure the attributes being used are trimmed when used:

An example of string functions trimming attribute values

This would turn

PSTLCITY: Vancouver

PSTLPROVBC  

POSTALCODE: V5V 0A1   

into

ADDRESSVancouver, BC, V5V 0A1

After processing, FME trimmed the leading and trailing whitespace and concatenated the separate attributes with commas.

Note

Notice the Date/Time functions in the Text Editor, which can be used to manipulate dates, times, and datetime strings, including TimeZone components.

Arithmetic Editor

The Arithmetic Editor is much the same as the Text Editor, except that FME evaluates whatever is entered into the dialog as an arithmetic expression and returns a numeric result:

An example of an arithmetic expression in the Arithmetic Editor

Here, the user calculates the monthly number of visitors to a park by dividing the annual number of visitors by 12 (twelve). As with the Text Editor, existing attributes and arithmetic functions are obtained from the menu on the left-hand side.

Note

The contents of the Arithmetic Editor must form an arithmetic expression that can be evaluated mathematically.

FME Feature Functions

One other item in the menu of both Text and Arithmetic Editors is the FME Feature Functions:

A list of FME Feature Functions

These are functions that use the very heart of FME's functionality. They are the building blocks that transformers are built upon, essential functionality that can return values to the editor.

For example, the @Area() function returns the area of the current record (assuming it is a polygon), while @CoordSys() returns the coordinate system. These functions are equivalent to using the AreaCalculator and CoordinateSystemExtractor transformers.

Some functions return strings; others return numeric values. Therefore, the available functions vary depending on whether you are using the Text or Arithmetic Editor is being used. In the screenshot above, the Text Editor functions are on the left, and the Arithmetic Editor functions on the right. The Text Editor can use either text or numeric values; the Arithmetic Editor can only ever accept numeric values.

FME Feature Functions are helpful because they allow you to build processing directly into the AttributeManager instead of using a separate transformer.

Replacing Other Transformers

Integrated Text and Arithmetic Editors provide an excellent benefit for workspace creation. They allow attribute-creating functions to be carried out directly in a single transformer.

For example, the AttributeManager Text Editor can be used as a direct replacement for the StringConcatenator and ExpressionEvaluator transformers.

The AttributeManager could also replace the StringPadder and AttributeTrimmer transformers, albeit with less user-friendliness. If FME Feature Functions are used inside the editor, this transformer could also technically replace transformers such as the AreaCalculator, LengthCalculator, DateTimeStamper, and many more.

This feature is usually a good thing. Workspaces will be more compact and well-defined when as many peripheral operations as possible are directly integrated into a single transformer. However, because an AttributeManager can carry out many operations, it is also critical to use best practices and ensure it has the proper annotation.

If an AttributeManager is not annotated correctly, it isn't possible to determine what action it carries out from looking at the Workbench canvas!

Exercise

Jennifer needs to to create and construct some new attributes to match the output schema:

1) Open Starting Workspace

AttributeManager in the workspace

2) Change Attribute Order

We want to move the newly-renamed province attribute down in the attribute order.

Move down button

New position for province

3) Set Attribute to a Fixed Value

Next, we'd like to create a new attribute, provider, and set it to Safe Software. 

Creating a new attribute

Entering a value

4) Set Attribute to a Variable Value

While setting attributes to a single, fixed value is sometimes required, more often you will find yourself setting an attribute value that will vary by record.

We want to do this for a new attribute called updateddate.

Adding another attribute

Opening the Text Editor

Inserting date time using Text Editor

5) Construct an Attribute

Next, we would like to create a new attribute constructed using other attributes. After creating it, we'd like to clean up by removing the attributes we used.

We want to concatenate ownernm1 and ownernm2 into a new attribute called owners and then remove those attributes afterward.

@Value(ownernm1 ) @Value(ownernm2)

@TrimRight(@Value(ownernm1) @Value(ownernm2))

6) Remove Attributes

Now that we have the owners field, she can remove the attributes ownernm1 and ownernm2. However, the order of operations is now essential. The AttributeManager must create owners in the parameters dialog before removing ownernm1 and ownernm2.

Removing attributes

Click OK.

7) View Results

Write out data using partial runs

Output data

Leave Us Feedback on This Lesson